$(function(){
		/*初始化表格*/
		var strInviteID=$("#strInviteID").val();
		$('#bidTender').datagrid({
    		url:'backbidtenderjson?strInviteID='+strInviteID,
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
			onLoadSuccess:function(data){
		        if (data.total == 0) { 
				//colspan为实际显示的总列数，appendRow、mergeCells不用修改
				$(this).datagrid('appendRow', { tenderID: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'tenderID', colspan: 6 }) 
				//隐藏分页导航条
				$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide(); 
				//隐藏选择框
				 $(this).datagrid('hideColumn', 'ck');
				} 
				//有数据时显示选择框、分页导航条
				else {
					$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
					$(this).datagrid('showColumn', 'ck');}
		    },
   			columns:[[
   			 	{field:'ck',checkbox:true},
   			 		{field:'inviteID',hidden:'true'},
				{field:'tenderID',title:'投标编码',align:'center',width:'13%',
				 formatter:function(value,row,index){
					if(row.inviteID == undefined)return row.tenderID;
					return'<a href="backbidtenderinfo?iTenderID='+row.tenderID+'">'+row.tenderID+'</a>'
				}},
				{field:'orgName',title:'投标公司',align:'center',width:'20%'},
				{field:'outDate',title:'出行日期',align:'center',width:'15%',formatter:function(value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            return year + "-" + month + "-" + day;
        }},
				{field:'backDate',title:'返程日期',align:'center',width:'15%',formatter:function(value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            return year + "-" + month + "-" + day;
        }},
				{field:'budget',title:'预算金额',align:'center',width:'15%'},
				
				{field:'state',title:'中标状态',align:'center',width:'20%',formatter: function(value,row,index){
	        
	         if(value == 1)
	        		return '未中标';
				else if(value == 2)
	        		return '中标';
				else
				return '终止';
	        }}
    		]]
		});
			
});

/*搜索*/
function searchTender(){
	
		var orgID = $("#searchOrgID").val();
		
		$("#bidTender").datagrid("load",{
			orgID:orgID
		})
	}
	
/*清空*/
function clearTender(){
        $("#searchOrgID").val('')
	
     }

// 后台招投细标模块查看投标明信息2020.12.03
function getBidDetailed(){
	
	var rows = $('#bidTender').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
		
		var iTenderID =  rows[0].tenderID; 
				location.href="/mmy/togetbiddetailed?iTenderID="+iTenderID;	
	}
}
//2020.12.03 hanxl 后台招标模块 中标
function winBidTender(){
	
	var rows = $('#bidTender').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 } else{
			var state = rows[0].state;
			if(state==1){
	if (confirm("确定选择此信息中标吗？")) {
			var iTenderID = rows[0].tenderID;
			var iInviteID = $("#strInviteID").val();
			$.ajax({
        url:"/mmy/winbidtender?iTenderID="+iTenderID+"&iInviteID="+iInviteID,
        type:"post",
        data:"",
        dataType:"text",
        success:function (data) {
			 location.reload();
		if(data==2){
			$.messager.alert('成功','选择成功','success');
			
			}
        },
        error:function () {
	$.messager.alert('错误','选择失败','error');
          
        }
    })
		}
		}else if(state==2){
			$.messager.alert('警告','该公司中标','warning');
			
		}else {
			$.messager.alert('警告','已有中标公司','warning');
			
		}
	}
}